<?php
namespace Dry\Base;

class Pdo {

    private $attr = array(
        \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
        \PDO::ATTR_PERSISTENT => false,
        \PDO::MYSQL_ATTR_INIT_COMMAND => 'set names utf8',
        \PDO::ATTR_ORACLE_NULLS => true,
        \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ
    );

    private $config = array();

    public function __construct($config)
    {
        $this->config['host'] = $config['host'];
        $this->config['port'] = $config['port'];
        $this->config['dbname'] = $config['dbname'];
        $this->config['username'] = $config['username'];
        $this->config['password'] = $config['password'];
    }

    public function get()
    {
        $config = $this->config;
        $dns = "mysql:host={$config['host']};port={$config['port']};dbname={$config['dbname']}";
        return new \PDO($dns, $config['username'], $config['password'], $this->attr);
    }

    public function getConfig()
    {
        return $this->config;
    }

}
?>
